<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use DB;

class BaseModel extends Model{
    /**
     * 批量插入数据
     * @param array $data
     * @return type
     */
    public function addAll(Array $data) {
        if($this->timestamps) {
            for($i=0; $i<count($data); $i++) {
                if(!isset($data[$i]['created_at'])) {
                    $data[$i]['created_at'] = date('Y-m-d H:i:s');
                }
            }
        }
        
        $rs = DB::table($this->getTable())->insert($data);
        return $rs;
    }
}
